using System;
using System.ComponentModel;

using DevExpress.Xpo;
using DevExpress.Data.Filtering;

using DevExpress.ExpressApp;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;

namespace WaTP.Module.BusinessObjects
{
    [DefaultClassOptions]
    public class Transport : CompanyBase
    {
        public Transport(Session session)
            : base(session)
        {
            // This constructor is used when an object is loaded from a persistent storage.
            // Do not place any code here or place it only when the IsLoading property is false:
            // if (!IsLoading){
            //    It is now OK to place your initialization code here.
            // }
            // or as an alternative, move your initialization code into the AfterConstruction method.
        }

        public override void AfterConstruction()
        {
            base.AfterConstruction();
            // Place here your initialization code.
        }
        [Association("TransportContacts-Transport")]
        public XPCollection<TransportContact> Contacts {
            get { return GetCollection<TransportContact>("Contacts"); }
        }
        [Association("Transport-Shipped")]
        public XPCollection<Shipped> Ships{
            get { return GetCollection<Shipped>("Ships");}
        }
    }

    public class TransportContact : PersonBase {
        public TransportContact(Session session)
            : base(session) { }
        private Transport transport;
        [Association("TransportContacts-Transport")]
        public Transport Transport {
            get { return transport; }
            set { SetPropertyValue("Transport", ref transport, value); }
        }
    }
    public class CompanyBase : BaseObject {
        public CompanyBase(Session session)
            : base(session) { }
        private string name;
        [RuleRequiredField(DefaultContexts.Save)]
        public string Name {
            get { return name; }
            set { SetPropertyValue("Name", ref name, value); }
        }
        private string address;
        [RuleRequiredField(DefaultContexts.Save)]
        public string Address {
            get { return address; }
            set { SetPropertyValue("Address", ref address, value); }
        }
        private string officePhone;
        [RuleRequiredField(DefaultContexts.Save)]
        public string OfficePhone {
            get { return officePhone; }
            set { SetPropertyValue("OfficePhone", ref officePhone, value); }
        }
        private string officePhone2;
        public string OfficePhone2 {
            get { return officePhone2; }
            set { SetPropertyValue("OfficePhone2", ref officePhone2, value); }
        }
        private string fax;
        public string Fax {
            get { return fax; }
            set { SetPropertyValue("Fax", ref fax, value); }
        }
        private string email;
        public string Email {
            get { return email; }
            set { SetPropertyValue("Email", ref email, value); }
        }
        private string website;
        public string Website {
            get { return website; }
            set { SetPropertyValue("Website", ref website, value); }
        }
    }

    public class PersonBase : BaseObject {
        public PersonBase(Session session)
            : base(session) { }
        private TitleOfCourtesy titleOfCourtesy;
        public TitleOfCourtesy TitleOfCourtesy {
            get { return titleOfCourtesy; }
            set { SetPropertyValue("TitleOfCourtesy", ref titleOfCourtesy, value); }
        }
        private string name;
        public string Name {
            get { return name; }
            set { SetPropertyValue("Name", ref name, value); }
        }
        private string mobilePhone;
        public string MobilePhone {
            get { return mobilePhone; }
            set { SetPropertyValue("MobilePhone", ref mobilePhone, value); }
        }
        private string email;
        public string Email {
            get { return email; }
            set { SetPropertyValue("Email", ref email, value); }
        }

        public override void AfterConstruction()
        {
            base.AfterConstruction();
            TitleOfCourtesy = TitleOfCourtesy.Mr;
        }
    }

    public enum TitleOfCourtesy { Mr, Ms}
}
